The reliability of a semiconductor memory varies depending on the pattern of the written values. Thus, the user data is encoded and written into the semiconductor memory in order to increase the reliability with the pattern. This encoding can improve the reliability for the written data.